#!/usr/bin/env bash
set -o errexit -o pipefail
DIR=$(dirname "${0}")
MAIN_DIR=$(readlink -f "${DIR}/..")
# shellcheck disable=SC2016
IMAGE=$(grep ^image: "${MAIN_DIR}/.gitlab-ci.yml" | \
        sed -e 's,^image: ,,g' | sed -e 's,\$CI_REGISTRY,registry.gitlab.com,g')

exec docker run -it --rm \
    --user $(id -u):$(id -g) \
    --mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}" \
    --workdir "${MAIN_DIR}" \
    "${IMAGE}" "${@}"
